<?php
namespace Tyrone\Command;
use Tyrone\Model\Game\PayLog;
use Tyrone\Model\Game\Role;
use Swoole\Coroutine;
class DayOnline extends Base
{

    protected $stat_project = 0;
    protected $day_online_type = 0;


    public  function execute()
    {
        $database = $this->database;
        $game_database = $this->game_mysql;
        $mysql = $this->mysql;
        $currentTimestamp = time();
        $date = date("Ymd", strtotime($this->sDate));

        $this->setFrequency(300);

        $roleModel = new Role($game_database);
        $payLogModel = new PayLog($game_database,$database);
        //当前在线数据
        $onlineInfo = $roleModel->getCurrentOnline(['is_online'=>1]);
        //return $this->result(compact('onlineInfo'));
        //此刻充值次数，充值金额，充值人数
        $payData = $payLogModel->statPay(['pay_date'=>$date]);
        //当月1号到此刻充值金额，次数，人数
        $payMonthData = $payLogModel->statPay([
            'pay_date[<>]' => [date("Ym01", strtotime($this->sDate)),$date],
        ]);
        //此刻登陆用户数
        $loginData = $roleModel->getCurrentOnline([
            "last_login_time[<>]"=>[strtotime($this->sDate . " 00:00:00"), strtotime($this->eDate . " 23:59:59")],
        ]);

        //此刻创角人数
        $regData = $roleModel->getCurrentOnline([
            "reg_time[<>]"=>[strtotime($this->sDate . " 00:00:00"), strtotime($this->eDate . " 23:59:59")],
        ]);
        $datas = compact('onlineInfo','payData','payMonthData','loginData','regData');

        //插入
        $DayOnline = new \Tyrone\Model\DayOnline($mysql);
        $day = date("Ymd", strtotime($date));
       foreach ($onlineInfo as $platform =>$item){
           $item += ['day'=>$day,'plat_server'=>$this->plat_server,'stat_project'=>1,'type'=>0];
           $other = ['master_platform'=>$this->platform];
           $DayOnline->insertData($item,$this->minus,'num',$other);
       }
        return $this->result($datas);
    }



    public function insertDayOnlineData($mysql,$date,$datas,$stat_project){
        $DayOnline = new \Tyrone\Model\DayOnline($mysql);
        $day = date("Ymd", strtotime($date));
        foreach ($datas as $platform =>$item){
            $item += ['day'=>$day,'plat_server'=>$this->plat_server,'stat_project'=>$stat_project,'type'=>$this->day_online_type];
            $other = ['master_platform'=>$this->platform];
            $DayOnline->insertData($item,$this->minus,'num',$other);
        }
    }


}